package com.flying.tradingservice.controller;

import com.flying.stockdetails.model.TradingCompany;
import com.flying.tradingservice.service.TradingCompanyClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;


@RestController
public class TradingCompanyController {
    private TradingCompanyClient client;

    public TradingCompanyController(TradingCompanyClient client) {
        this.client = client;
    }

    @GetMapping(value = "/details", produces = {MediaType.APPLICATION_JSON_VALUE})
    public Flux<TradingCompany> listTradingCompanies() {
        return this.client.findAllCompanies();
    }

    @GetMapping(value = "/details/{ticker}", produces = {MediaType.APPLICATION_JSON_VALUE})
    public Mono<TradingCompany> getTradingCompany(@PathVariable String ticker) {
        return this.client.getTradingCompany(ticker);
    }

}
